package edu.nctu.csie.jichang.spring;

import java.io.IOException;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.ResourceEntityResolver;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.FileSystemXmlApplicationContext;


public class EnhanceFileSystemXmlApplicationContext extends FileSystemXmlApplicationContext{

	public EnhanceFileSystemXmlApplicationContext(String pPath) {
		super(pPath);
	}
	
	@Override
	protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory)throws BeansException, IOException {
		// Create a new XmlBeanDefinitionReader for the given BeanFactory.
		XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
		beanDefinitionReader.setDocumentReaderClass(EnhanceBeanDefinitionDocumentReader.class);
		// Configure the bean definition reader with this context's
		// resource loading environment.
		beanDefinitionReader.setResourceLoader(this);
		beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));
		// Allow a subclass to provide custom initialization of the reader,
		// then proceed with actually loading the bean definitions.
		initBeanDefinitionReader(beanDefinitionReader);
		loadBeanDefinitions(beanDefinitionReader);
	}
	
	// convert protected to public
	public String[] getConfigLocations() {
		return super.getConfigLocations();
	}

}
